'use strict';
import React, {Component} from 'react';
import {InteractionManager,Text,View} from 'react-native';
import Common from '../common/constants';


import LoginContainer          from '../containers/LoginContainer';
import SpaceListContainer      from '../containers/SpaceListContainer';
import SpaceMapContainer      from '../containers/SpaceMapContainer';
// // import WebContainer            from '../containers/WebContainer';
// // import ProductContainer        from '../containers/ProductContainer';
// // import UploadImageContainer    from '../containers/UploadImageContainer';
import UIContainer             from '../containers/UIContainer';
import CertifyContainer        from '../containers/CertifyContainer';
import BaiduContainer          from '../containers/BaiduContainer';
// import MyContainer             from '../containers/MyContainer';

import {getIcon} from '../common/icons';

import {NavigationPage, ListRow, Badge,Toast,Input} from 'teaset';

export const _eventDeal=(thiz,item)=>
{
    if(item!=undefined&&item._E!=undefined)
    {
        let aim=Object.assign({},item);
        if(aim._C!=undefined)aim._C="";
        if(aim._S!=undefined)aim._S="";
        if(item._E=='go')
        {
            console.log('go page：',item);
            const { navigator,userReducer } = thiz.props;
            if(item._login&&(!userReducer.user||!userReducer.user.access_token))
            {
                Toast.fail(item._msg?item._msg:'请您先登录');
                thiz.props.navigator.push({name: 'LoginContainer',component: LoginContainer,passProps: {...thiz.props,...aim,}})

            }else goPage(thiz,item.pageName,aim)
        }
        else if(item._E=='back')//后退一页
        {
            const { navigator } = thiz.props;
            navigator.pop();
        }
        else if(item._E=='home')//调回主页
        {
            const { navigator } = thiz.props;
            let routes=navigator.getCurrentRoutes();
            let destination='';
            for (var i=0;i<routes.length;i++) {if(routes[i].name=="mainpage"){destination=routes[i];break;}}

            if(destination)navigator.popToRoute(destination);
            else navigator.pop();
        }
        else if(item._E=='doCertify')//实名认证
        {
            // _doCertify(thiz,item.pageName,aim)
        }
    }
}



export const goPage = (that,pageName,item) => {
    // console.log('Go.goPage.goPagegoPagegoPagegoPagegoPagegoPagegoPagegoPagegoPage');

            // else if (pageName=='Web'){navigatorParam.component=WebContainer;}
            // else if (pageName=='Product'){navigatorParam.component=ProductContainer;}
            // else if (pageName=='SubCategory'){navigatorParam.component=SubCategoryContainer;}
            // else if (pageName=='Category'){navigatorParam.component=CategoryContainer;}
            // else if (pageName=='UploadImage'){navigatorParam.component=UploadImageContainer;}
            // else if (pageName=='MyOrderList'){navigatorParam.component=MyOrderListContainer;}
            // else if (pageName=='UI1'){navigatorParam.component=UI1Container;}
     InteractionManager.runAfterInteractions(() => 
        {
            let navigatorParam={};
            navigatorParam.name=pageName;
            let passProps={reqData:item};
                 if (pageName=='Login'){navigatorParam.component=LoginContainer;}
            else if (pageName=='Baidu'){navigatorParam.component=BaiduContainer;}
            else if (pageName=='My'){navigatorParam.component=MyContainer;}
            else if (pageName=='UI'){navigatorParam.component=UIContainer;}
            else if (pageName=='SpaceList'){navigatorParam.component=SpaceListContainer;}
            else if (pageName=='SpaceMap'){navigatorParam.component=SpaceMapContainer;}
            else if (pageName=='Certify'){navigatorParam.component=CertifyContainer;}
            passProps.task_id=(item.task_id==undefined?'':item.task_id);
            passProps.id=(item.id==undefined?'':item.id);
            passProps.pageId=(item.pageId==undefined?'':item.pageId);
            passProps.title=(item.title==undefined?'':item.title);
            passProps.uri=(item.uri==undefined?'':item.uri);
            navigatorParam.passProps=passProps;
            that.props.navigator.push(navigatorParam);
        });
};


/*
对象形式提供
*/
export const _updateStateObject=(thiz,name,value)=>
{
    let formItems=thiz.state.formItems;
    // console.log('formItems:',formItems);
    let exist=false;
    for (var key in formItems) 
    {
        if(name==key){
            formItems[key]=value;
            exist=true;
            break;
        }
    }
    if(!exist)formItems[name]=value;
    thiz.setState({formItems:formItems});
}




//输入栏
// item={name:'id_no',title:'身份证号',icon:'../images/zhcs/certify.png',value:'44010****',placeholder:'请输入身份证号码',size:'md'}
// export const _renderInputRow=(thiz,item,il)=>
// {
//     // console.log('item:',item)
//     // item._S=_arrCssDeal(item._S);
//     let props={key:il};
//     // if(item.title)props.title=item.title;

//     let ipt={key:il};
//     // if(item.placeholder)ipt.placeholder=item.placeholder;
//     // if(item.value)ipt.defaultValue=item.value;
//     // if(item.size)ipt.size=item.size;
//     // else ipt.size='md' ;


//     // if(item.icon)props.icon=getIcon(item.icon);
//     //     <ListRow {...props}
//     //     detail={<Input autoCapitalize={'none'} autoCorrect={false} {...ipt} style={{width: Common.window.width*2/3}}  
//     //                 onChangeText={text =>{_updateStateObject(thiz,item.name,text)}} />} 
//     //             />


//     return  (
//         <ListRow {...props}
//         detail={<Input autoCapitalize={'none'} autoCorrect={false} {...ipt} style={{width: Common.window.width*2/3}}  
//                     onChangeText={text =>{_updateStateObject(thiz,item.name,text)}} />} 
//                 />
                
//             )




// }


export const _renderInputRow=(thiz,item,il)=>
{
    let props={key:il};
    if(item.title)props.title=item.title;

    let ipt={};
    if(item.placeholder)ipt.placeholder=item.placeholder;
    if(item.value)ipt.defaultValue=item.value;
    if(item.size)ipt.size=item.size;
    else ipt.size='md' ;


    if(item.icon)props.icon=getIcon(item.icon);

    return  (
        <ListRow {...props}
        detail={<Input autoCapitalize={'none'} autoCorrect={false} {...ipt} style={{width: Common.window.width*2/3}}  
                    onChangeText={text =>{_updateStateObject(thiz,item.name,text)}} />} 
                />
                
            )




}